package com.fce.boc.bean;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fce.boc.exception.ErrorCodeAndMsg;
import lombok.Getter;

@Getter
@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
public class ReturnMsg<T>{


    //请求成功返回码为：0000
    private static final String successCode = "0000";
    //返回数据
    private T data;
    //返回码
    private String code;
    //返回描述
    private String msg;

    private ReturnMsg() {
        this.code = successCode;
        this.msg = "请求成功";
    }

    private ReturnMsg(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ReturnMsg error(ErrorCodeAndMsg errorCodeAndMsg){
        ReturnMsg responseResult=new ReturnMsg(errorCodeAndMsg.getCode(),errorCodeAndMsg.getMsg());
        return responseResult;
    }
    public static ReturnMsg error(String code, String msg){
        ReturnMsg responseResult=new ReturnMsg(code,msg);
        return responseResult;
    }

    public static ReturnMsg success(){
        return new ReturnMsg();
    }
    public ReturnMsg setData(T data){
        this.data=data;
        return this;
    }

}
